package com.my12306.train.controller;

import com.my12306.common.model.vo.PageVo;
import com.my12306.common.util.PageUtils;
import com.my12306.common.util.response.ResponseData;
import com.my12306.train.model.entity.PlanEntity;
import com.my12306.train.service.PlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 路线计划
 *
 * @author ËÕÄÁÏ¦
 * @email
 * @date 2020-07-24 20:58:07
 */
@RestController
@RequestMapping("/plan")
public class PlanController {
    @Autowired
    private PlanService planService;

    /**
     * 列表
     */
    @PostMapping("/list")
    public ResponseData list(@RequestBody PageVo pageVo) {
        PageUtils page = planService.queryPlanPage(pageVo);
        return ResponseData.ok().put("page", page);
    }

    /**
     * 获取修改/新增参数
     */
    @GetMapping("/add/para")
    public ResponseData getParameters(@RequestParam(value = "id",required = false) Long id){
        return  planService.getAddParameters(id);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public ResponseData info(@PathVariable("id") Long id) {
        PlanEntity plan = planService.getById(id);

        return ResponseData.ok().put("plan", plan);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public ResponseData save(@RequestBody PlanEntity plan) {
      return   planService.savePlan(plan);
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public ResponseData update(@RequestBody PlanEntity plan) {
       planService.updateById(plan);

        return ResponseData.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public ResponseData delete(@RequestBody List<Long> ids) {
        planService.deletePlanBatchByIds(ids);
        return ResponseData.ok();
    }

}
